package org.ecype.diego;

import android.content.ContentUris;
import android.net.Uri;

public class Uris extends ContentUris {

	private static final String SEGMENT_SEPARATOR = "/";

	private Uris() {
	}

	public static Uri append(Uri uri, String segment) {
		return Uri.parse(uri + SEGMENT_SEPARATOR + segment);
	}

	public static Uri append(Uri uri, long id, String segment) {
		return append(ContentUris.withAppendedId(uri, id), segment);
	}

	public static Uri withoutLastSegment(Uri action) {
		String actionAsString = action.toString();
		int lastIndexOfSegmentSeparator = actionAsString.lastIndexOf(SEGMENT_SEPARATOR);
		return Uri.parse(actionAsString.substring(0, lastIndexOfSegmentSeparator));
	}

	public static Uri parse(String string) {
		return Uri.parse(string);
	}

	public static long parseId(Uri uri) {
		return Long.parseLong(uri.getPathSegments().get(1));
	}

}
